package com.dzf.controller;

import com.dzf.Util.SessionUtil;
import com.dzf.entity.RespJson;
import com.dzf.entity.User;
import com.dzf.service.RateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/rate/")
public class RateController {
    @Autowired
    RateService rateService;
    @Autowired
    SessionUtil sessionUtil;

    @RequestMapping("/likeBlog/{blogid}")
    @ResponseBody
    public RespJson likeBlog(@PathVariable("blogid") String blogid)
    {
        System.out.println("blogid:"+blogid);
        User user = sessionUtil.getUser();
        return rateService.likeBlog(user.getId(), blogid);
    }

    @RequestMapping("/findByUserLike/{blogid}")
    @ResponseBody
    public RespJson findByUserLike(@PathVariable("blogid") String blogid){
        User user = sessionUtil.getUser();
        return RespJson.success(200,"ok",rateService.findByUserLike(blogid,user.getId()));
    }
}
